"""
ababaaa
"""
import pymysql

kwargs = {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "123456",
    "database": "stu",
    "charset": "utf8"
}
# 连接数据库
db = pymysql.connect(**kwargs)

# 创建游标:使用sql语句获取数据操作结果的对象
cur = db.cursor()

# # 存储文件
# with open("dielailo.jpg", "rb") as fr:
#     data = fr.read()
# sql = "update class set image=%s where id =1"
# cur.execute(sql, [data])
# db.commit()

# 提取文件
sql = "select name,image from class where id=1"
cur.execute(sql)
name, image = cur.fetchone()
with open(name + ".jpg", "wb")as fw:
    fw.write(image)
